//
//  CustomContainerView.m
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/11.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomContainerView.h"
#import <Masonry/Masonry.h>
#import "ABButton.h"

@interface CustomContainerView()

@end
@implementation CustomContainerView

- (void)setBackgroundImage:(UIImage *)backgroundImage {
    _bgImageView.image = [backgroundImage stretchImageWithInsetsTop:150 left:150 bottom:150 right:150];
}

- (UIImage *)backgroundImage {
    return _bgImageView.image;
}

- (void)setRightButton:(ABButton *)rightButton {
    [self addSubview:rightButton];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bgImageView).offset(3);
        make.right.equalTo(_bgImageView).offset(-30);
    }];
}

- (void)setRightButtons:(NSArray<ABButton *> *)rightButtons {
    [rightButtons enumerateObjectsUsingBlock:^(ABButton *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self addSubview:obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_bgImageView).offset(3);
            make.right.equalTo(_bgImageView).offset(-(100 * idx) - (idx == 0 ? 10 : 0));
        }];
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [_bgImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(18, 1, 53, 20));
        }, ^{ //竖屏
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 30, 13, 20)); //阴影10个点宽度
        });
    }];
    [_container mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(61, 32, 62, 30));
        }, ^{ //竖屏
            make.edges.equalTo(self).insets(UIEdgeInsetsMake(45, 62, 23, 30));
        });
    }];
}

- (void)setup {
    _container = [[UIView alloc] init];
    _bgImageView = [[UIImageView alloc] init];
    [self addSubview:_bgImageView];
    [self addSubview:_container];
}

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

@end
